package com.fuqi.android.zhongcai.base.view.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.business.shuig.request.result.OrderListResult;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ChouChaShowActivity;
import com.fuqi.android.zhongcai.utils.ActivityUtils;
import com.fuqi.framework.utils.StringUtil;

import java.util.List;

/**
 * create by juner
 * @Date 2016-8-31
 */


public class YiChouChaAdapter extends BaseRecyclerViewAdapter<OrderListResult>{
    Context mContext;

    public YiChouChaAdapter(Context context,List<OrderListResult> datas) {
        super(datas);
        this.mContext = context;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.adapter_yi_choucha;
    }

    @Override
    protected void onBind(ViewHolder holder, int position,OrderListResult data) {
        holder.setTextView(R.id.tv_install_address, data.getAddArea());
        holder.setTextView(R.id.tv_order_origin, data.getContactName());

        if(!hasPunish(data.getPunishAmount())) {
            holder.setTextView(R.id.tv_order_status, "无");
            holder.get(R.id.btn_order_status).setVisibility(View.GONE);
        }else {
            holder.setTextView(R.id.tv_order_status, "有");
            holder.get(R.id.btn_order_status).setTag(data.getOrderId());
            holder.get(R.id.btn_order_status).setVisibility(View.VISIBLE);
            holder.get(R.id.btn_order_status).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String ordid = v.getTag().toString();
                    if(StringUtil.isNotEmpty(ordid)){
                        Bundle bundle = new Bundle();
                        bundle.putString("order_id",v.getTag().toString());
                        ActivityUtils.startActivity(mContext.getApplicationContext(), ChouChaShowActivity.class, bundle);
                    }
                }
            });
        }
    }

    boolean hasPunish(String punishAmount){
        int iAmount = StringUtil.parseInt(punishAmount);
        if(iAmount > 0) return true;
        return false;
    }
}
